package heap;

import java.io.IOException;

import global.AttrType;
import global.EID;
import global.PID;
import global.PageId;
import global.RID;
import global.TID;

public class Triple extends Tuple {

	private static short numFlds = 7;
	private static short [] strSizes = null;
	private static AttrType [] types = {new AttrType (AttrType.attrInteger),
										new AttrType (AttrType.attrInteger),
										new AttrType (AttrType.attrInteger),
										new AttrType (AttrType.attrInteger),
										new AttrType (AttrType.attrInteger),
										new AttrType (AttrType.attrInteger), 
										new AttrType (AttrType.attrReal)};
	
	
	
	public Triple () throws InvalidTypeException, InvalidTupleSizeException, IOException {
		super (46);
		this.setHdr(numFlds, types, strSizes);
	}
	
	public Triple (Tuple tup) {
		data = tup.getTupleByteArray();
	    tuple_length = tup.getLength();
	    tuple_offset = 0;
	    fldCnt = tup.noOfFlds(); 
	    fldOffset = tup.copyFldOffset();
	}
	
	public Triple(byte[] b, int i, int j) {
		super(b, i, j);
	}

	public EID getSubjectID () throws FieldNumberOutOfBoundException, IOException {
		return new EID (new PageId(this.getIntFld(1)), this.getIntFld(2));
	}
	
	public PID getPredicateID () throws FieldNumberOutOfBoundException, IOException {
		return new PID (new PageId(this.getIntFld(3)), this.getIntFld(4));
	}
	
	public EID getObjectID () throws FieldNumberOutOfBoundException, IOException {
		return new EID (new PageId(this.getIntFld(5)), this.getIntFld(6));
	}
	
	public float getConfidence () throws FieldNumberOutOfBoundException, IOException {
		return this.getFloFld(7);
	}
	
	public void setConfidence (float confidence) throws FieldNumberOutOfBoundException, IOException {
		this.setFloFld (7, confidence);
	}
	
	public void printTuple () throws FieldNumberOutOfBoundException, IOException {
		System.out.println(this.getIntFld(1) + "," + this.getIntFld(2));
		System.out.println(this.getIntFld(3) + "," + this.getIntFld(4));
		System.out.println(this.getIntFld(5) + "," + this.getIntFld(6));
		System.out.println(this.getFloFld(7));
	}
	
	public void addTriple (RID seid, RID pid, RID oeid, float d) throws FieldNumberOutOfBoundException, IOException {
		this.setIntFld (1, seid.pageNo.pid);
		this.setIntFld (2, seid.slotNo);
		this.setIntFld (3, pid.pageNo.pid);
		this.setIntFld (4, pid.slotNo);
		this.setIntFld (5, oeid.pageNo.pid);
		this.setIntFld (6, oeid.slotNo);
		this.setFloFld (7, d);
	}
	
	/**
	 * 
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
	}

}


